﻿Public Class Pregunta_Secreta
   
    Enum termino
        aprobado
        rechazado
    End Enum

    Dim cargarcombos As New combo
    Dim acceso As New acceso_a_datos

    Private Sub Pregunta_Secreta_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        acceso._tabla = "Pregunta_Secreta"
        cargarcombos.cargar(cmb_pregunta, acceso.leo_tabla(), "descripcion", "cod_Pregunta")

    End Sub


    Private Function modificar() As termino

        Dim tabla As New Data.DataTable
        Dim modificacion As String = ""
        Dim usuario As String = frm_Acceso.txt_usuario.Text + frm_olvide_Constraseña.txt_usuario.Text

        modificacion = "UPDATE Empleado Set "
        modificacion &= "cod_Pregunta = " & Me.cmb_pregunta.SelectedValue
        modificacion &= ", res_Pregunta = '" & Me.mask_rta.Text & "'"
        modificacion &= " WHERE nombre_Usuario = '" & usuario & "'"
        acceso._modificar(modificacion)

        Return termino.aprobado

    End Function



    Private Sub btn_aceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_aceptar.Click
        If Me.mask_rta.Text = "" Then
            'MessageBox.Show("Tenes que completar el campo Respuesta", "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information)
            mask_rta_Leave(sender, e)
            mask_rta.Focus()
        Else
            Me.modificar()
            MessageBox.Show("Se establecio tu Pregunta Secreta", "Felicidades", MessageBoxButtons.OK, MessageBoxIcon.Information)
            Me.Close()
        End If
    End Sub

    Private Sub btn_volver_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_volver.Click
        Me.Close()
        UsuarioContraseña.Show()
        Me.mask_rta.Text = ""
    End Sub

    Private Sub Pregunta_Secreta_FormClosed(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed
        Dispose()
    End Sub

    Private Sub mask_rta_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mask_rta.Leave
        If mask_rta.Text = "" And btn_volver.Focused = False Then
            lbl_pregunta_obligatorio.Visible = True
        Else
            lbl_pregunta_obligatorio.Visible = False
        End If
    End Sub
End Class